<?php
require('../include/init.inc.php');
$method = $id_num = '';
extract($_REQUEST, EXTR_IF_EXISTS);

if (Common::isPost()) {
    Common::checkParam($id_num);
    $product = AdminProducts::getProductById($id_num);
    if (empty($product)) {
        Common::exitWithError(ErrorMessage::PRODUCT_NOT_EXIST, "one_page_shop/home_binding.php");
    }
    $where1 = "WHERE products_id = " . $id_num;
    $update_data['products_index'] = 1;
    $result = AdminProducts::update($where1, $update_data);
    //其他产品全部关闭
    if ($result) {
        $update_data_close['products_index'] = 0;
        $where = "WHERE products_id  != " . $id_num;
        $rt = AdminProducts::update($where, $update_data_close);

        if ($rt) {
            SysLog::addLog(UserSession::getUserName(), 'MODIFY', 'HomeBind', $id_num, json_encode($update_data));
            Common::exitWithSuccess('更新完成', 'one_page_shop/home_binding.php');
        } else {
            OSAdmin::alert("error");
        }
    }
}

Template::display('one_page_shop/home_binding.tpl');